import pygame
import sys
import time
import random
from pygame.locals import *
from spaceship import Spaceship
from shot import Shot
from point import Point
from asteroid import Asteroid


screen_dimension = ( 800, 400 ) 

asteroidsbac = pygame.image.load('asteroidsbac.png')#.convert()
asteroidsbac = pygame.transform.scale( asteroidsbac, screen_dimension)

pygame.init()

pygame.display.set_caption('')
#screen = pygame.display.set_mode( (800,400), pygame.FULLSCREEN )
screen = pygame.display.set_mode( screen_dimension )
shots = []
spaceship = Spaceship()
asteroid = Asteroid(Point(0,0,6,0))



angle = 0

while True:
    screen.blit( asteroidsbac, (0,0))
    asteroid.move()
    asteroid.paint(screen)
    spaceship.paint(screen)    
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            output = spaceship.handle_keydown(event)
            if ( output != None ):
                shots.append(output);            
            if event.key == K_ESCAPE:
                sys.exit()
        if event.type == KEYUP:
            spaceship.handle_keyup(event)
    
    shots_in_screen = []
    for shot in shots:
        shot.move()
        #for asteroi in asteroid :
         
        if ( shot.collides(asteroid) ):
            asteroid.point.x = 0
            asteroid.point.x = 0
        else:
            if ( shot.is_in_screen() ):
                shot.paint(screen)
                shots_in_screen.append(shot)
            
    shots = shots_in_screen
    
    spaceship.move()

    pygame.display.update()
    time.sleep(0.06)